home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / +ORC / Orc pac 8 / HOWTO81.TXT < prev    next >
Encoding:
Text File  |  2000-05-25  |  17.6 KB  |  332 lines

  1.                      HOW TO CRACK, by +ORC, A TUTORIAL
  2.  
  3. ---------------------------------------------------------------------------
  4.  
  5.                Lesson 8.1: How to crack Windows, an approach
  6.  
  7. ---------------------------------------------------------------------------
  8.  
  9.                                 [WINPGP.EXE]
  10.  
  11.                    --------------------------------------
  12.  
  13. --------------------------------------------------------
  14.      SPECIAL NOTE: Please excuse the somehow "unshaven"
  15.      character of the windows lessons... I'm cracking the
  16.      newest Windows '95 applications right now, therefore
  17.      at times I had to add "on the fly" some corrections to
  18.      the older Windows 3.1 and Windows NT findings.
  19.                 "homines, dum docent, discunt".
  20. ---------------------------------------------------------
  21. ->   1st THING TO REMEMBER
  22. The NE format does give every windows executable the equivalent
  23. of a debug symbol table: A CRACKER BLISS!
  24.  
  25. ->   UNDOCUMENTED DEBUGGING
  26. One of the many feature of Windows based on undocumented
  27. foundations is the "ability to debug".
  28. A word about undocumented functions in the MS-Operating Systems:
  29. Microsoft manipulates its rule and domination of the operating
  30. systems in use to day (MS-DOS, Windows, Windows '95) with two
  31. main wicked aims:
  32. 1)   getting the concurrence completely bankrupt (that's the
  33.      scope of all the using of undocumented functions and
  34.      CHANGING them as soon as the concurrence uses them). The
  35.      battle against Borland was fought in this way.
  36. 2)   getting all future "programmers" to use windows as a "black
  37.      box" that only Microsoft engineers (if ever) can master, so
  38.      that everybody will have to sip the ill-cooked abominations
  39.      from Microsoft without ever having a chance to alter or
  40.      ameliorate them.
  41. Strange as it may seem, only the sublime cracker community fights
  42. against these intolerable plans. All stupid governments and
  43. lobbies -on the contrary- hide behind the fig-leaf of the
  44. "market" "freedom" in order to ALLOW such heinous developments
  45. (I'm speaking as if they were capable to opposing them even if
  46. they wanted, which they do not. Be assured, they couldn't anyway,
  47. "Governments" are deliberately MADE to serve Gates and all the
  48. remaining suckers, and lobbies are the shield of feudalism. You
  49. can forget "democracy", the only rule existing is a malevolent
  50. oligarchy based on money, personal connections, defect of
  51. culture, lack of knowledge and dictatorship of bad taste through
  52. television in order to keep the slaves tamed... enough now...)
  53. The windows situation is particularly reminiscent of the older
  54. situation in DOS, where for years the key "load but don't
  55. execute" function, used by debuggers, such as [DEBUG], [SYMDEB]
  56. and [CODEVIEW], was "reserved" by Microsoft.
  57.      The windows debugging library, WINDEBUG.DLL, a number of
  58. undocumented functions and even the interface it provides are
  59. undocumented! The WinDebug() function is used by all available
  60. windows debuggers, including [CVW] (CodeView for Windows), [TDW]
  61. (TurboDebugger for Windows), [Multiscope] and [Quick C for
  62. Windows] (the last two are GUI, not text debuggers. The use of
  63. WinDebug() doesn't show up in MAPWIN output 'coz debuggers link
  64. to it at run-time via the amazing GetProcAddress() function.
  65.      WinDebug() is a hacked 32-bit version, for the old Windows
  66. 3.0, of the poorly documented DOSPTrace() function from OS/2 1.x
  67. (study these older Operating Systems! Studying the past you'll
  68. understand EVERYTHING! Sometime I think that the only way to hack
  69. and crack correctly is to be more a software historian than a
  70. programmer... fac sapias et liber eris!). DOSPTrace is, in turn,
  71. based on the ptrace() function in Unix.
  72.      Like DosPTrace(), WinDebug() takes commands such as Go,
  73. Single-Step, Write&Read Registers, Write&Read Memory. It returns
  74. to its caller either when the command completes or when a
  75. breakpoint occurs (or a DLL load). These commands and
  76. notifications appear in a large structure whose address is passed
  77. in WinDebug().
  78.      WinDebug() was renamed CVWIN.DLL (and TDWIN.DLL) for Windows
  79. 3.1., all crackers should study it and get the maximum possible
  80. documentation about it. As you will see in the following, it is
  81. worth to study also TOOLHELP.DLL (what Microsoft would like you
  82. to fiddle with) and INT_41h (the real debugging interface).
  83.  
  84. Interrupt handling under Windows
  85.      Interrupt handling under Windows can be tricky: you need to
  86. use Toolhelp (a rather scaring lobotomy for your programs) or to
  87. have special code for Standard vs. Enhanced modes, because the
  88. information on the stack of an interrupt or exception handler
  89. differs between the two windows modes. In addition, some handlers
  90. would be installed using INT_21h, while others are set up using
  91. DPMI services. Toolhelp has quite a bit of internal code that
  92. "cooks" the interrupts and sends them to you in an easily
  93. digestible form.
  94.      Remember that Windows uses GP faults as a "hacker" method
  95. of doing ring transitions that are not allowed with legal 80x86
  96. instructions: the virtual memory system of Enhanced mode is
  97. implemented via the page fault.
  98.  
  99. Some tools for cracking windows (-> see lesson 9)
  100. -----------------          DEBUGGERS
  101. CVW and TDW         (you have to know the function's
  102.                     segment:offset address beforehand in order
  103.                     to crack a function)
  104. WCB                 [Windows Codeback] by Leslie Pusztai (it's
  105.                     a really cool tool!)
  106. WDEB386             Microsoft's WDEB386 (clumsy, and requires a
  107.                     second monitor)
  108. Soft-Ice/Windows    best (BY FAR!) windows debugger! NuMega is
  109.                     so good I am at times really sorry to crack
  110.                     their products! [WINICE] is the single,
  111.                     absolutely essential debugger and snooping
  112.                     utility for windows crackers. Get it!
  113.  
  114. -----------------   POST MORTEM INSPECTORS
  115. CORONER, etc.            (a lot of shareware)
  116. MS-DrWatson              Old and clumsy
  117. Borland's Winspector     THE BEST! It has the BUILDSYM utility
  118.                          that allows the creation of a debug
  119.                          .SYM file from an .EXE without debug
  120.                          information.
  121.  
  122. -----------------         INSPECTORS
  123. MS-Spy                   Old
  124. Borland's WinSight       (Best one, select "Other")
  125. MicroQuill's Windows DeMystifiers (from Jeff Richter):
  126.      VOYEUR (hold SHIFT picking Message Selection), COLONEL,
  127.      MECHANIC and ECOLOGIST
  128.  
  129. -----------------          SNOOPERS
  130. [INFSPY.EXE], 231.424 bytes, version 2.05 28/8/1994 by Dean
  131. Software Design, may be the more complete one.
  132. [SUPERSPY.EXE], 24.576 bytes, 10,6,1994, quite handy for quick
  133. informations.
  134. [WINVIEW.EXE], 30.832 bytes, Version 3.00 by Scott McCraw, MS(c)
  135. 1990-1992, this is the old MS-Spy, distributed by MS
  136. [TPWSPY.EXE], 9.472 bytes, quite primitive, but you get the
  137. pascal source code with it.
  138.  
  139. ->   INSIDE A WINDOWS '95 DEBUGGER
  140.      You can debug a program at the assembly-language level
  141. without any debugging information. The DOS [DEBUG] program does
  142. that, allowing breakpoints and single-stepping, all of which
  143. implies that the hardware must be cooperating. Back in the time
  144. of the 4-MHz Z-80s, you used a debugger that plugged interrupt
  145. op codes into the instruction stream to generate breakpoints.
  146.      Nothing has changed. That's how you debug a program on a
  147. 80586 (=Pentium). The x86 architecture includes software
  148. interrupts. The 1-byte op code xCC is the INT_03 instruction,
  149. reserved for debuggers. You can put the INT_03 op code in place
  150. of the program instruction op code where the break is to occur
  151. and replace the original op code at the time of the interrupt.
  152. In the 80386 and later, you can set a register flag that tells
  153. the processor to generate a not-intrusive INT_01 instruction for
  154. every machine instruction executed. That device supports single
  155. stepping.
  156.      The Win32SDK (Windows '95 software developer's kit) includes
  157. functions that allow one program to launch another program and
  158. debug it. The SDK's debug API takes care of how the interrupts
  159. and interrupt vectors get managed. The logical consequence of
  160. such an approach is that fewer and fewer people will be able to
  161. know what's going on inside an application. The bulk of the
  162. programmers -in few years time- will not be able any more to
  163. reverse engineer an application, unless the few that will still
  164. understand assembler-language do offer them the tools to do it.
  165. Microsoft -it is evident- would like the programmers to use a
  166. "black box" approach to programming, writing nice little "hallo
  167. world" application and leaving to the engineers in Microsoft
  168. alone the capacity to push forward (and sell) real programs that
  169. are not toy application.
  170.      The Win32 documentation seems vast, almost luxurious, until
  171. you begin serious work and you discover its shortcomings, like
  172. the fact that extended error codes are not documented, and
  173. numerous APIs are documented either incorrectly or so poorly that
  174. you must burn precious time testing them. What we definitely need
  175. is to find some secret fellows inside Microsoft (like good old
  176. Prometeus) that smuggles to the outside the real documentation
  177. that the Microsoft engineers have reserved for themselves. If you
  178. are reading this and do work for Microsoft, consider the
  179. possibility of double-crossing your masters for the sake of
  180. humanity and smuggle us the secret information.
  181.      In windows '95 a debugger program launches a program to be
  182. debugged by calling the _CreateProcess function, specifying in
  183. an argument that the program is to be debugged. Then the debugger
  184. program enters a loop to run the program. At the top of the loop
  185. the debugger calls _WaitForDebugEvent.
  186.      Each time _WaitForDebugEvent returns it sets indicators that
  187. tell about the vent that suspended the program being debugged.
  188. This is where the debugger traps breakpoints and single-step
  189. exceptions. _WaitForDebugEvent fills in an event structure that
  190. contains among other things the address that was interrupted end
  191. the event that caused the interrupt.
  192.      The debugger calls _GetThreadContext to get the running
  193. context of the debugged program, including the contents of the
  194. registers. The debugger can, as the result of cracker
  195. interaction, modify these values and the contents of the debugged
  196. program's memory.
  197.      The debugger sets breakpoints by saving the op code at the
  198. instruction to be intercepted and putting the INT_03 op code at
  199. its place, it's always the same old marmalade. When the
  200. breakpoint occurs, the debugger replaces the original op code in
  201. the program's instruction memory, and decrements the interrupted
  202. program counter in the saved context so that execution resumes
  203. at the instruction that was broken.
  204.      To single-step a program, the debugger sets a bit in the
  205. context's flags register that tells the processor to generate an
  206. INT_01 for every instruction cycle. When that interrupt occurs,
  207. the debugger checks to see if the interrupted address is at a new
  208. source-code line number. If not, the debugger continues
  209. execution. Otherwise, the debugger displays the new line in the
  210. IDE and waits for the cracker to take an action that resumes the
  211. program.
  212.      While the debugged program is suspended, the debugger
  213. interacts with the cracker and provides full access to the
  214. debugged program's context and memory. This access permits the
  215. cracker to examine and modify part of the code.
  216.      To resume the debugged program, the debugger resets the
  217. program's context by calling _SetThreadContext and calls
  218. _ContinueDebugEvent. Then, the debugger returns to the top of the
  219. loop to call _WaitForDebugEvent again.
  220.      To extract debug information from a Win32 executable file,
  221. you must understand the format of that file (best thing to do,
  222. to practice yourself, would be to reverse engineer small
  223. programs). The executable file has two sections not found in
  224. other executable files: ".stab" and ".stabstr". How nice that
  225. they used names that suggest their purpose (nomen est omen).
  226. You'll find them inside a table of fixed-length entries that
  227. include entries for .text, .bss, .data and .idata. Inside these
  228. sections the compilers put different parts of a program.
  229.      There are several different formats for encoding debug
  230. information in an executable file. Borland's Turbo Debugger  one
  231. format. Microsoft's CodeView  another. The gnu-win32 port from
  232. Cygnus the stab format, an acronym meaning "symbol table",
  233. although the table contains much more than just symbol
  234. information.
  235.      The .stab section in a portable executable file is a table
  236. of fixed-length entries that represent debugging information in
  237. the stab format. The .stabstr section contains variable-length,
  238. null terminated strings into which the .stab table entries point.
  239.      The documentation for the stab format is available in text
  240. format on the Cygnus ftp site (ftp.cygnus.com//pub/gnu-win32).
  241.      Stabs contain, in a most cryptic format, the names and
  242. characteristics of all intrinsic and user-defined types, the
  243. memory address of every symbol in external memory and on the
  244. stack, the program counter address of every function, the program
  245. counter address where every brace-surrounded statement block
  246. starts and ends, the memory address of line numbers within
  247. source-code files, and anything else that a debugger needs. The
  248. format is complex and cryptic because it is intended to support
  249. any source-code language. It is the responsibility of a debugger
  250. program to translate the stab entries into something meaningful
  251. to the debugger in the language being debugged.
  252.  
  253.      Windows '95 invokes dozens of INT_21 services from 32-bit
  254. code, including KERNEL32.DLL and possess Krn32Mutex, which
  255. apparently controls access to certain parts of the kernel. Some
  256. of the functions in KERNEL32 can be blocked by the Win16Mutex,
  257. even though Microsoft says this isn't the case.
  258.  
  259. SO, I WANNA CRACK, WHAT SHOULD I DO?
  260.      I'll show you a simple windows crack, so easy it can be done
  261. without WINICE: let's take [WINPGP4.1.] (front-end for PGPing in
  262. windows, by Geib - I must thank "Q" for the idea to work on this
  263. crack).
  264.      Using WCB you'll find out quickly that the "CONGRATULATIONS
  265. your registration number is OK" and the "SORRY, your registration
  266. number is not correct" data blocks are at the block starting at
  267. 36.38B8 (respectively at 36.38D5 and 36.3937), that relocs to
  268. 13.081B.
  269.      Looking at 13.0000 and following code, you'll find a push
  270. 38D5 (68D538) and a push 3937 (683739) at 13.064D and 13.06AE.
  271.      The road to the crack is now open, you just need to find and
  272. "fool" the calling routines. You'll learn the exact procedures
  273. for this kind of WINcracks in part 2 and 3 of -> Lesson 8. Let's
  274. now have a look at the protection scheme (disassembly from WCB):
  275. ...
  276. 13.0E88   660FBF46F8     movsx     eax, word ptr [bp-08]
  277. 13.0E8D   668946F4       mov       [bp-0C], eax
  278. 13.0E91   668B46F4       mov       eax, [bp-0C]
  279. 13.0E95   6669C00A000300 imul      eax, 0003000A
  280. 13.0E9C   668946F0       mov       [bp-10], eax
  281. 13.0EA0   668B4606       mov       eax, [bp+06]
  282. 13.0EA4   663B46F0       cmp       eax, [bp-10]
  283. 13.0EA8   7505           jne       0EAF      <- beggar_off
  284. 13.0EAA   B80100         mov       ax, 0001  <- flag 1 = "Right!"
  285. 13.0EAD   EB04           jmp       0EB3      <- and go on
  286. beggar_off:
  287. 13.0EAF   33C0           xor       ax,ax     <- flag 0 = "Nope!"
  288. 13.0EB1   EB00           jmp       0EB3      <- and go on
  289.  
  290.      I want you to have a good look at this protection scheme.
  291. IT'S THE SAME OLD SOUP! You do remember lesson 3 and the
  292. protection schemes of the old DOS stupid games of the '80s, don't
  293. you? IT'S THE SAME OLD SOUP! In this "up-to-date" "new" windows
  294. application, in WINPGP version 4.1 of 1995/1996, exactly the same
  295. kind of protection is used to "conceal" the password!
  296. A)   compare user input with memory echo
  297. B)   beggar off if not equal with AX=0
  298. C)   go on if equal with AX=1... how boring!
  299.      Besides, look at all the mov eax, and  eax, moves preceding
  300. the compare! That's a typical pattern for these "number_password"
  301. protections! I wrote (years ago) a little crack utility that
  302. searches for code blocks with a "66" as first instruction_byte
  303. repeating in four or more consecutive instructions and it still
  304. allows me to crack more than half of these windows password smuts
  305. in less than three seconds flat. The IMUL instruction creates the
  306. "magic" number, and if you give a closer look at the mathematical
  307. part of the "conceal" routine, it could help you to crack
  308. analogous schemes used in order to protect the "Instant access"
  309. (c) & (tm) time_crippled software :=)
  310.      Now you could crack the above code in 101 different ways,
  311. the most elegant one would probably substitute je 0EAF (or jZ
  312. 0EAF, that's the same) to the jne 0EAF at 13.0EA8. You just write
  313. a 74 at the place of the 75, like you did for the cracks in
  314. 1978... how boring: it's really the same old soup! (But you'll
  315. see some new tricks in the next lessons).
  316.  
  317. Well, that's it for this lesson, reader. Not all lessons of my
  318. tutorial are on the Web.
  319.      You 'll obtain the missing lessons IF AND ONLY IF you mail
  320. me back (via anon.penet.fi) with some tricks of the trade I may
  321. not know that YOU discovered. Mostly I'll actually know them
  322. already, but if they are really new you'll be given full credit,
  323. and even if they are not, should I judge that you "rediscovered"
  324. them with your work, or that you actually did good work on them,
  325. I'll send you the remaining lessons nevertheless. Your
  326. suggestions and critics on the whole crap I wrote are also
  327. welcomed.
  328.  
  329.                                 E-mail +ORC
  330.  
  331.                          +ORC 526164@anon.penet.fi
  332.